package com.resource.utils;

import com.resource.service.OfficeTokenService;
import com.resource.spring.ApplicationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;

/**
 * http工具类
 *
 * @Author: xianggaoxiong
 * @Date: 2020-09-25 15:45
 **/
public class HttpUtils {

	/**
	 * 获取 org.springframework.http.HttpEntity
	 *
	 * @param jsonParam
	 * @param httpMethod
	 * @return
	 */
	public static <T> HttpEntity<T> setHttpEntity(HttpMethod httpMethod, T jsonParam,String userId) {
		OfficeTokenService officeTokenService = ApplicationUtils.getBean(OfficeTokenService.class);
		String token = officeTokenService.getToken(userId);
		HttpHeaders headers = new HttpHeaders();
		headers.set("Authorization", "Bearer " + token);
		switch (httpMethod) {
		case GET:
			break;
		default:
			headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
		}
		return new HttpEntity<>(jsonParam, headers);
	}

}
